package com.typing.battle.util;

import android.content.*;
import android.preference.*;
import android.util.*;

public class PreferenceMgr {
    SharedPreferences prefs;
    SharedPreferences.Editor editor;
    private Context mContext;
    
    public static final String REGISTRATION_KEY = "registration_key";
    public static final String PHONE_NUMBER_KEY = "phone_number_key";
    public static final String USER_EMAIL_KEY = "user_email_key";
    public static final String USER_PASSWORD_KEY = "user_password_key";
    public static final String USER_NAME_KEY = "user_name_key";
    public static final String USER_DESCRIPT_KEY = "user_descript_key";
    public static final String USER_AGE_KEY = "user_age_key";
    public static final String USER_SEX_KEY = "user_sex_key";
    
    
    public static PreferenceMgr instance;
    
    public PreferenceMgr(Context context){
	    mContext = context;
	    prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
	    editor =PreferenceManager.getDefaultSharedPreferences(mContext).edit();
	}
   
    public static PreferenceMgr getInstance(Context context){
    	if(instance == null) instance = new PreferenceMgr(context);
    	return instance;
    }
    
    public void removeData(String key){
        Log.d("","removeData ===>>"+key);
        editor.remove(key);
        editor.commit();
    }   
   
    public boolean setData(String key, boolean val){    
        try{     
	        editor.putBoolean(key, val);
	        editor.commit();
	        Log.d("", "setData>> key :"+key +", defaultVal :" + val);
	
	        return true;
        }catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    
    public boolean setData(String key, String val){    
        try{
            editor.putString(key, val);
            editor.commit();
            Log.d("","setData>> key :"+key +", defaultVal :" + val);
            return true;
        }catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
   
    public boolean setData(String key, int val){    
    	try{
    		editor.putInt(key, val);
    		editor.commit();
    		Log.d("", "setData>> key :"+key +", val :" + val);
    		return true;
    	}catch (Exception e) {
    		e.printStackTrace();
    		return false;
    	}
    }
   
    
    public int getData(String key, int defaultVal){    
    	Log.d("","getData>>"+key +"==>>"+prefs.getInt(key,defaultVal));
    	return prefs.getInt(key,defaultVal);
    }
    
    public boolean getData(String key, boolean defaultVal){    
    	Log.d("","getData>>"+key +"==>>"+ prefs.getBoolean(key,defaultVal));
    	return prefs.getBoolean(key,defaultVal);
    }
    
    public String getData(String key, String defaultVal){    
    	Log.d("","getData>>"+key +"===>>"+prefs.getString(key,defaultVal));
    	return prefs.getString(key,defaultVal);
    }   
}
